//
//  CLTopicTextCell.m
//  chanlin
//
//  Created by Ryan on 14-12-16.
//  Copyright (c) 2014年 chanlin. All rights reserved.
//

#import "CLTopicTextCell.h"
#import "UIView+Utils.h"

@interface CLTopicTextCell()
//@property (nonatomic, strong) UIImageView *frameImg;

@property (nonatomic, strong) UIImageView *topFrameImg;
@property (nonatomic, strong) UIImageView *middleFrameImg;
@property (nonatomic, strong) UIImageView *bottomFrameImg;

@property (nonatomic, strong) UILabel *abstractLab;

@property (nonatomic,strong) NSMutableArray *bgImgarr;

@end
@implementation CLTopicTextCell

- (void)uiInit{
    [super uiInit];
    
    self.topFrameImg = [[UIImageView alloc]init];
    [self.topFrameImg setImage:[UIImage imageNamed:@"topic_ abstract_frame_top.png"]];
    [self.contentView addSubview:self.topFrameImg];
    
    self.bottomFrameImg = [[UIImageView alloc]init];
    [self.bottomFrameImg setImage:[UIImage imageNamed:@"topic_ abstract_frame_bottom.png"]];
    [self.contentView addSubview:self.bottomFrameImg];

    
    self.abstractLab = [[UILabel alloc]init];
    self.abstractLab.backgroundColor = [UIColor whiteColor];
    self.abstractLab.font = [UIFont systemFontOfSize:16];
    self.abstractLab.textAlignment = NSTextAlignmentCenter;
    self.abstractLab.textColor = RGB(0x54, 0x54, 0x54);
    [self.contentView addSubview:self.abstractLab];
    
    
    self.message=[[IFLabel2 alloc] init];
    self.message.font=[UIFont systemFontOfSize:16];
    self.message.textAlignment=kCTTextAlignmentLeft;
    self.message.textColor=RGB(0x5b, 0x85, 0x9e);
    self.message.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
    [self.contentView addSubview:self.message];
    
    self.bgImgarr=@[].mutableCopy;
}

- (void)loadTopicData:(CLTopic *)newsList{
    [super loadTopicData:newsList];
    
    self.topFrameImg.frame = CGRectMake(11, 18, GlobleWidth-22.f, 7.5);
    
    int count = (newsList.cHeight-25-22  )/6;
    
    if(self.bgImgarr &&self.bgImgarr.count!=count){
        for(UIView *view1 in self.bgImgarr){
            [view1 removeFromSuperview];
        }
        
    for (int i = 0; i<count; i++) {
        self.middleFrameImg = [[UIImageView alloc]init];
        self.middleFrameImg.frame = CGRectMake(11, 18+7.5+i*6, GlobleWidth-22.f, 6);
        [self.middleFrameImg setImage:[UIImage imageNamed:@"topic_ abstract_frame_middle.png"]];
        [self.contentView addSubview:self.middleFrameImg];
        [self.bgImgarr addObject:self.middleFrameImg];
    }
    }
    
    
    self.bottomFrameImg.frame = CGRectMake(11, newsList.cHeight-1.5-22, GlobleWidth-22.f, 1.5);
    
    
    self.abstractLab.text = _isStrNotNull(newsList.slider1)?newsList.slider1: @" 摘要";
    UIFont *fnt = [UIFont systemFontOfSize:16.f];
    _abstractLab.font = fnt;
    // 根据字体得到NSString的尺寸
    CGSize size = [_abstractLab.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:fnt,NSFontAttributeName, nil]];
    self.abstractLab.frame = CGRectMake(25, 11, size.width+10, 16);
    
    self.message.frame=CGRectMake(11+12, 15+18, GlobleWidth-22.f-24, newsList.cHeight-22);
    self.message.text=newsList.title;
}

@end
